home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / VISUALBA / DATAEX.ZIP / DATASAMP.FRM < prev    next >
Text File  |  1993-07-06  |  11KB  |  447 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Data Control Example"
  4.    ClientHeight    =   4155
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1575
  7.    ClientWidth     =   7020
  8.    Height          =   4560
  9.    Left            =   1035
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4155
  12.    ScaleWidth      =   7020
  13.    Top             =   1230
  14.    Width           =   7140
  15.    Begin TextBox Text1 
  16.       DataField       =   "bitfield"
  17.       DataSource      =   "data1"
  18.       Height          =   285
  19.       Left            =   2400
  20.       TabIndex        =   18
  21.       Top             =   360
  22.       Width           =   1215
  23.    End
  24.    Begin CommandButton cmdGrid 
  25.       Caption         =   "Show Grid"
  26.       Height          =   375
  27.       Left            =   4200
  28.       TabIndex        =   17
  29.       Top             =   3720
  30.       Width           =   1095
  31.    End
  32.    Begin CommandButton cmdEnd 
  33.       Caption         =   "End"
  34.       Height          =   375
  35.       Left            =   5640
  36.       TabIndex        =   16
  37.       Top             =   2520
  38.       Width           =   1095
  39.    End
  40.    Begin TextBox txtID 
  41.       DataField       =   "scount"
  42.       DataSource      =   "Data1"
  43.       Enabled         =   0   'False
  44.       Height          =   285
  45.       Left            =   600
  46.       TabIndex        =   0
  47.       Top             =   360
  48.       Width           =   1335
  49.    End
  50.    Begin CommandButton cmdDelete 
  51.       Caption         =   "Delete"
  52.       Height          =   375
  53.       Left            =   4200
  54.       TabIndex        =   12
  55.       Top             =   1320
  56.       Width           =   1095
  57.    End
  58.    Begin CommandButton cmdCancel 
  59.       Caption         =   "Cancel"
  60.       Height          =   375
  61.       Left            =   4200
  62.       TabIndex        =   11
  63.       Top             =   3120
  64.       Width           =   1095
  65.    End
  66.    Begin CommandButton cmdSave 
  67.       Caption         =   "Save"
  68.       Height          =   375
  69.       Left            =   4200
  70.       TabIndex        =   10
  71.       Top             =   2520
  72.       Width           =   1095
  73.    End
  74.    Begin CommandButton cmdAdd 
  75.       Caption         =   "Add"
  76.       Height          =   375
  77.       Left            =   4200
  78.       TabIndex        =   9
  79.       Top             =   1920
  80.       Width           =   1095
  81.    End
  82.    Begin CommandButton cmdUpdate 
  83.       Caption         =   "Update"
  84.       Enabled         =   0   'False
  85.       Height          =   375
  86.       Left            =   4200
  87.       TabIndex        =   8
  88.       Top             =   720
  89.       Width           =   1100
  90.    End
  91.    Begin CommandButton cmdFind 
  92.       Caption         =   "Find"
  93.       Height          =   375
  94.       Left            =   4200
  95.       TabIndex        =   7
  96.       Top             =   120
  97.       Width           =   1100
  98.    End
  99.    Begin CommandButton cmdLast 
  100.       Caption         =   "Last"
  101.       Height          =   375
  102.       Left            =   5640
  103.       TabIndex        =   6
  104.       Top             =   1920
  105.       Width           =   1100
  106.    End
  107.    Begin CommandButton cmdFirst 
  108.       Caption         =   "First"
  109.       Height          =   375
  110.       Left            =   5640
  111.       TabIndex        =   5
  112.       Top             =   1320
  113.       Width           =   1100
  114.    End
  115.    Begin CommandButton cmdPrior 
  116.       Caption         =   "Prior"
  117.       Height          =   375
  118.       Left            =   5640
  119.       TabIndex        =   4
  120.       Top             =   720
  121.       Width           =   1100
  122.    End
  123.    Begin CommandButton cmdNext 
  124.       Caption         =   "Next"
  125.       Height          =   375
  126.       Left            =   5640
  127.       TabIndex        =   3
  128.       Top             =   120
  129.       Width           =   1100
  130.    End
  131.    Begin TextBox txtFirstName 
  132.       DataField       =   "class"
  133.       DataSource      =   "Data1"
  134.       Height          =   375
  135.       Left            =   600
  136.       TabIndex        =   2
  137.       Top             =   1920
  138.       Width           =   3135
  139.    End
  140.    Begin TextBox txtLastName 
  141.       DataField       =   "name"
  142.       DataSource      =   "Data1"
  143.       Height          =   375
  144.       Left            =   600
  145.       TabIndex        =   1
  146.       Top             =   1080
  147.       Width           =   3135
  148.    End
  149.    Begin Data Data1 
  150.       Caption         =   "Data1"
  151.       Connect         =   ""
  152.       DatabaseName    =   "asample.MDB"
  153.       Exclusive       =   0   'False
  154.       Height          =   270
  155.       Left            =   600
  156.       Options         =   0
  157.       ReadOnly        =   0   'False
  158.       RecordSource    =   "student"
  159.       Top             =   2640
  160.       Width           =   3135
  161.    End
  162.    Begin Label Label1 
  163.       Caption         =   "BitField"
  164.       Height          =   255
  165.       Left            =   2400
  166.       TabIndex        =   19
  167.       Top             =   120
  168.       Width           =   975
  169.    End
  170.    Begin Label lblID 
  171.       Caption         =   "Scount"
  172.       Height          =   255
  173.       Left            =   600
  174.       TabIndex        =   15
  175.       Top             =   120
  176.       Width           =   1095
  177.    End
  178.    Begin Label lblFirstName 
  179.       Caption         =   "Class"
  180.       Height          =   255
  181.       Left            =   600
  182.       TabIndex        =   14
  183.       Top             =   1680
  184.       Width           =   1335
  185.    End
  186.    Begin Label lblLastName 
  187.       Caption         =   "Name"
  188.       Height          =   255
  189.       Left            =   600
  190.       TabIndex        =   13
  191.       Top             =   840
  192.       Width           =   975
  193.    End
  194. End
  195. Option Explicit
  196.  
  197. Const SIZE = 11
  198.  
  199.  
  200. Dim sQuote As String
  201. Dim src As String
  202. Dim criteria As String
  203. Dim currentrecord As String
  204.  
  205. Const ERROR_MSG = "You have entered an Employee ID that already exists. Modify Employee ID before proceeding."
  206.  
  207. Const KEY_DELETE = &H2E
  208.  
  209. Sub cmdAdd_Click ()
  210.  
  211.     currentrecord = data1.Recordset.Bookmark
  212.  
  213.     data1.Recordset.AddNew
  214.     
  215.     'Show Save and Cancel - Disable Delete
  216.     cmdSave.Visible = True
  217.     cmdCancel.Visible = True
  218.     cmdDelete.Enabled = False
  219.     
  220.     txtID.Enabled = True
  221.     txtID.SetFocus
  222. End Sub
  223.  
  224. Sub cmdCancel_Click ()
  225.     
  226.     'Restore position to where you were
  227.     'when you started Adding records
  228.      data1.Recordset.Bookmark = currentrecord
  229.  
  230.     'Reset buttons to show leaving Add mode
  231.     ReSetButtons
  232. End Sub
  233.  
  234. Sub cmdDelete_Click ()
  235.     On Error Resume Next
  236.  
  237.     data1.Recordset.Delete
  238.     data1.Recordset.MoveNext
  239.     
  240.     'If the last record was just deleted, move to the
  241.     'new last record
  242.     If data1.Recordset.EOF Then
  243.         data1.Recordset.MoveLast
  244.     End If
  245. End Sub
  246.  
  247. Sub cmdEnd_Click ()
  248.     Unload form1
  249. End Sub
  250.  
  251. Sub cmdFind_Click ()
  252.     sQuote = Chr$(34)
  253.  
  254.     'If Save is visible - you were in the middle of adding
  255.     'Hide Save/Cancel to show ADD was cancelled.
  256.     cmdSave.Visible = False
  257.     cmdCancel.Visible = False
  258.  
  259.     'Save the current position.
  260.     currentrecord = data1.Recordset.Bookmark
  261.  
  262.     src = InputBox$("Enter last name of employee to find", "Find Box")
  263.     If src = "" Then Exit Sub
  264.     
  265.     criteria = "[Last Name] = " & sQuote & src & sQuote
  266.     data1.Recordset.FindFirst criteria
  267.     
  268.     If data1.Recordset.NoMatch Then
  269.         MsgBox "No Record Found!", , "What were you thinking?"
  270.         data1.Recordset.Bookmark = currentrecord
  271.     Else
  272.         cmdNext.Enabled = True
  273.         cmdPrior.Enabled = True
  274.     End If
  275. End Sub
  276.  
  277. Sub cmdFirst_Click ()
  278.     data1.Recordset.MoveFirst
  279.     cmdNext.Enabled = True
  280.     cmdPrior.Enabled = False
  281. End Sub
  282.  
  283. Sub cmdGrid_Click ()
  284.     form1.Hide
  285.     LoadFrame
  286.     form2.Show
  287. End Sub
  288.  
  289. Sub cmdLast_Click ()
  290.     data1.Recordset.MoveLast
  291.     cmdPrior.Enabled = True
  292.     cmdNext.Enabled = False
  293. End Sub
  294.  
  295. Sub cmdNext_Click ()
  296.  
  297.     data1.Recordset.MoveNext
  298.     cmdPrior.Enabled = True
  299.     
  300.     If data1.Recordset.EOF Then
  301.         data1.Recordset.MoveLast
  302.         cmdNext.Enabled = False
  303.     End If
  304.  
  305. End Sub
  306.  
  307. Sub cmdPrior_Click ()
  308.     
  309.     data1.Recordset.MovePrevious
  310.     cmdNext.Enabled = True
  311.     If data1.Recordset.BOF Then
  312.